class LoginController < ApplicationController

  def login

    if request.post? and params[:user]
      @user = User.new(params[:user])
      user = User.find_by_user_name(@user.user_name)

      if user and user.password_matches?(@user.password)
        session[:user_id] = user.id
        redirect_to :controller => :main_page, :action => :main
      else
        flash[:notice] = I18n.t :invalid_user
      end
    else
      @user = User.new()
    end
  end
end
